from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, Http404

from . import models


def index(request):
    books = models.Book.objects.all()
    context = {'books': books, 'total': len(books)}
    return render(request, "app1/index.html", context=context)


def detail(request, pk):
    book = get_object_or_404(models.Book, pk=pk)
    context = {'book': book}
    return render(request, "app1/detail.html", context=context)


def about(request):
    return render(request, "app1/about.html")
